/**
 * 
 */

package CCT220_Aula14_Exercicio02_13106.control;


import java.util.Vector;

import CCT220_Aula14_Exercicio02_13106.model.Aluno;
import CCT220_Aula14_Exercicio02_13106.view.LimiteAluno;


/**
 * </br>******************************
 * </br>Project: CCT220
 * </br>Package: CCT220_Aula14_Exercicio02_13106.control
 * </br>Class: ControleAluno
 * </br>Last Change: 04/10/2011 23:35:10
 * </br>Description: Controls the operations for a list of Aluno and your view
 * </br>******************************</br>
 * 
 * @author marcel
 * @author 13106
 * 
 */
public class ControleAluno {
	private final Vector<Aluno> listaAluno;


	/* private final LimiteAluno objLimiteAluno; */

	/**
	 * </br>******************************
	 * </br>Constructor for
	 * </br>Package: CCT220_Aula14_Exercicio02_13106.control
	 * </br>Class: ControleAluno
	 * </br>LastChange: 04/10/2011 23:35:20
	 * </br>******************************</br>
	 * 
	 */
	public ControleAluno() {

		listaAluno = new Vector<Aluno>();
		/* objLimiteAluno = */new LimiteAluno(this);
	}


	/**
	 * </br>******************************
	 * </br>Package: CCT220_Aula14_Exercicio02_13106.control
	 * </br>Class: ControleAluno
	 * </br>Method: insereAuno
	 * </br>Last Change: 04/10/2011 23:35:26
	 * </br>Description: Add a new Aluno to listaAluno
	 * </br>******************************</br>
	 * 
	 * @param pCodigo
	 * @param pNome
	 * @param pEndereco
	 * @param idade
	 * @throws Exception
	 */
	public void insereAuno(int pCodigo, String pNome, String pEndereco,
	        int idade) throws Exception {

		listaAluno.add(new Aluno(pCodigo, pNome, pEndereco, idade));
	}


	/**
	 * </br>******************************
	 * </br>Package: CCT220_Aula14_Exercicio02_13106.control
	 * </br>Class: ControleAluno
	 * </br>Method: imprimeAlunos
	 * </br>Last Change: 04/10/2011 23:35:31
	 * </br>Description: Get all the Aluno.toString() from listaAlunos
	 * </br>******************************</br>
	 * 
	 * @return the result
	 */
	public String imprimeAlunos() {

		String result = "";
		for (int intIdx = 0; intIdx < listaAluno.size(); intIdx++) {
			Aluno objAluno = listaAluno.elementAt(intIdx);
			result += (objAluno.toString() + "\n");
		}
		return result;
	}


	/**
	 * </br>******************************
	 * </br>Package: CCT220_Aula14_Exercicio02_13106.control
	 * </br>Class: ControleAluno
	 * </br>Method: imprimeAluno
	 * </br>Last Change: 04/10/2011 23:35:37
	 * </br>Description: Get the Aluno.toString() from listaAluno
	 * </br>******************************</br>
	 * 
	 * @param pCodigo
	 * @return the result
	 */
	public String imprimeAluno(int pCodigo) {

		String result = "";
		for (int intIdx = 0; intIdx < listaAluno.size(); intIdx++) {
			Aluno objAluno = listaAluno.elementAt(intIdx);
			if (objAluno.getCodigo() == pCodigo) {
				result = objAluno.toString() + "\n";
				break;
			}
		}
		return result;
	}


	/**
	 * </br>******************************
	 * </br>Package: CCT220_Aula14_Exercicio02_13106.control
	 * </br>Class: ControleAluno
	 * </br>Method: removeAluno
	 * </br>Last Change: 04/10/2011 23:35:45
	 * </br>Description: Remove Aluno from listaAluno
	 * </br>******************************</br>
	 * 
	 * @param pCodigo
	 * @return the result
	 */
	public String removeAluno(int pCodigo) {

		String result = "";
		for (int intIdx = 0; intIdx < listaAluno.size(); intIdx++) {
			Aluno objAluno = listaAluno.elementAt(intIdx);
			if (objAluno.getCodigo() == pCodigo) {
				result = listaAluno.elementAt(intIdx).toString();
				listaAluno.removeElementAt(intIdx);
			}
		}
		return result;
	}

}
